package com.geekstudy.week5.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedHashMap;
import java.util.Map;

@Service
public class Exercise10HikariService {

    @Autowired
    private DataSource dataSource;

    public Map<String, Object> hikari() throws SQLException {
        Map<String, Object> resultMap = new LinkedHashMap<String, Object>();

        Connection connection = dataSource.getConnection();
        Statement statement = connection.createStatement();
        String deleteSql = "delete from geek_study where id in ('hi1001') ";
        boolean deleteResult = statement.execute(deleteSql);
        resultMap.put(deleteSql, deleteResult);

        String insertSql = "insert into geek_study(id, name, nick_name, address) values('hi1001', 'Hikari1001', 'Hikari nickName1001', 'Hikari 2021')";
        boolean result = statement.execute(insertSql);
        resultMap.put(insertSql, result);

        return resultMap;
    }
}
